package org.jeecg.modules.cshApp.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.cshApp.entity.CshCitiesEntity;
import org.jeecg.modules.cshApp.entity.CshRotationChartEntity;
import org.jeecg.modules.cshApp.entity.CshStoreTypeEntity;
import org.jeecg.modules.cshApp.service.ICshAdressService;
import org.jeecg.modules.cshApp.service.ICshRotationChartEntityService;
import org.jeecg.modules.cshApp.service.ICshStoreTypeEntityService;
import org.jeecg.modules.cshApp.vo.CshAdressModule;
import org.jeecg.modules.cshbasic.entity.CshStoreEntity;
import org.jeecg.modules.cshbasic.service.ICshStoreEntityService;
import org.jeecg.modules.cshbasicfiles.entity.CshBrandeEntity;
import org.jeecg.modules.cshbasicfiles.service.ICshBrandeEntityService;
import org.jeecg.modules.cshonlinebusiness.entity.CshNewcarEntity;
import org.jeecg.modules.cshonlinebusiness.service.ICshNewcarEntityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @description 车生活app开放接口
 * @author 许泽平
 * @Date 2020-04-07
 * @version V1.0
 */
@RestController
@RequestMapping("/csh/openinterface")
@Slf4j
@Api(tags="车生活app开放接口")
public class CshOpenInterfaceController {


    @Autowired
    private ICshRotationChartEntityService cshRotationChartEntityService;

    @Autowired
    private ICshNewcarEntityService cshNewcarEntityService;

    @Resource
    private ICshAdressService cshAdressService;

    @Autowired
    private ICshStoreEntityService cshStoreService;

    @Autowired
    private ICshBrandeEntityService cshBrandeEntityService;

    @Autowired
    private ICshStoreTypeEntityService cshStoreTypeEntityService;


    /**
     * 轮播图分页列表展示
     *
     * @param cshRotationChartEntity
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @RequestMapping(value = "/listChart", method = RequestMethod.GET)
    @ApiOperation("轮播图分页")
    public Result<?> queryPageList(CshRotationChartEntity cshRotationChartEntity,
                                   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                   HttpServletRequest req) {
        QueryWrapper<CshRotationChartEntity> queryWrapper = QueryGenerator.initQueryWrapper(cshRotationChartEntity, req.getParameterMap());
        Page<CshRotationChartEntity> page = new Page<CshRotationChartEntity>(pageNo, pageSize);
        IPage<CshRotationChartEntity> pageList = cshRotationChartEntityService.page(page, queryWrapper);
        return Result.ok(pageList);
    }

    /**
     * 新车分页
     *
     * @param cshNewcarEntity
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @ApiOperation("新车分页")
    @RequestMapping(value = "/listNewCar", method = RequestMethod.GET)
    public Result<?> queryPageList(CshNewcarEntity cshNewcarEntity,
                                   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                   HttpServletRequest req) {
        QueryWrapper<CshNewcarEntity> queryWrapper = QueryGenerator.initQueryWrapper(cshNewcarEntity, req.getParameterMap());
        Page<CshNewcarEntity> page = new Page<CshNewcarEntity>(pageNo, pageSize);
        IPage<CshNewcarEntity> pageList = cshNewcarEntityService.page(page, queryWrapper);
        return Result.ok(pageList);
    }

    /**
     * 获取所有省份信息
     *
     * @return 返回所有省份信息
     */
    @ApiOperation("获取所有省市区")
    @RequestMapping(value = "/listProvince", method =  RequestMethod.GET)
    public Result<?> findAllProAndCityAndArea(){
        List<CshAdressModule> allProAndCityAndArea = cshAdressService.findAllProAndCityAndArea();
        return Result.ok(allProAndCityAndArea);
    }

    /**
     * 获取福建省市辖区
     *
     * @return 返回福建省市辖区
     */
    @ApiOperation("获取厦门省市区")
    @RequestMapping(value = "/openXmProvince", method =  RequestMethod.GET)
    public Result<?> findXmCity(){
        CshAdressModule fjAreas = cshAdressService.findFjAreas("350000");
        return Result.ok(fjAreas);
    }

    /**
     * 获取开通城市
     *
     * @return 返回开通城市
     */
    @ApiOperation("开通城市")
    @RequestMapping(value = "/openFjCities", method =  RequestMethod.GET)
    public Result<?> openCities(){
        List<CshCitiesEntity> openCities = cshAdressService.findByOpenCity();
        return Result.ok(openCities);
    }

    /**
     * 开放获取车生活门店
     *
     * @param cshStore
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @ApiOperation("门店权限分页")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result<?> queryPageList(CshStoreEntity cshStore,
                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                   HttpServletRequest req) {
        QueryWrapper<CshStoreEntity> queryWrapper = QueryGenerator.initQueryWrapper(cshStore, req.getParameterMap());
        Page<CshStoreEntity> page = new Page<CshStoreEntity>(pageNo, pageSize);
        IPage<CshStoreEntity> pageList = cshStoreService.page(page, queryWrapper);

        return Result.ok(pageList);
    }

    /**
     * 分页品牌
     *
     * @param cshBrandeEntity
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @ApiOperation("品牌分页")
    @RequestMapping(value = "/listBrand", method = RequestMethod.GET)
    public Result<?> queryPageList(CshBrandeEntity cshBrandeEntity,
                                   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                   HttpServletRequest req) {
        QueryWrapper<CshBrandeEntity> queryWrapper = QueryGenerator.initQueryWrapper(cshBrandeEntity, req.getParameterMap());
        Page<CshBrandeEntity> page = new Page<CshBrandeEntity>(pageNo, pageSize);
        IPage<CshBrandeEntity> pageList = cshBrandeEntityService.page(page, queryWrapper);
        return Result.ok(pageList);
    }

    /**
     * 门店类型
     *
     * @param cshStoreTypeEntity
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @RequestMapping(value = "/listStoreType")
    public Result<?> queryPageList(CshStoreTypeEntity cshStoreTypeEntity,
                                   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                   HttpServletRequest req) {
        QueryWrapper<CshStoreTypeEntity> queryWrapper = QueryGenerator.initQueryWrapper(cshStoreTypeEntity, req.getParameterMap());
        Page<CshStoreTypeEntity> page = new Page<CshStoreTypeEntity>(pageNo, pageSize);
        IPage<CshStoreTypeEntity> pageList = cshStoreTypeEntityService.page(page, queryWrapper);
        return Result.ok(pageList);
    }
}
